/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package econutri.servicos;

import econutri.persistencia.entidades.Usuario;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Leonardo Oliveira Moreira
 * 
 */
public class GenericFilter implements Filter {

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        /*
        HttpSession session = ((HttpServletRequest) request).getSession();
        if (session == null || session.getAttribute("usuario") == null || !(session.getAttribute("usuario") instanceof Usuario)) {
            ((HttpServletResponse) response).sendRedirect("LogoutServlet");
        }
        */
        long startTime = System.currentTimeMillis();

        HttpServletRequest requestTemp = (HttpServletRequest) request;
        String servletName = requestTemp.getServletPath();
        if (servletName != null && servletName.startsWith("/"))
            servletName = servletName.substring(1);
        System.out.println("### Service name: " + servletName);

        chain.doFilter(request, response);

        long stopTime = System.currentTimeMillis();
        //System.out.println("### Time to execute request: " + (stopTime - startTime) + " milliseconds");
    }

    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void destroy() {
    
    }

}
